﻿using Cherry.Agile.Framework;
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cherry.Agile.Scheduler
{
    class JobProxy<TJob> : IJob where TJob : IJob, new()
    {
        public TJob Job { get; private set; }

        public JobProxy()
        {
            Job = new TJob();
        }

        public JobProxy(TJob job)
        {
            if (job == null)
                throw new ArgumentNullException("job");
            this.Job = job;
        }

        public void Execute(IJobExecutionContext context)
        {
            const string exceptionPolicy = "WCF";
            try
            {
                this.Job.Execute(context);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex, exceptionPolicy);
            }
        }
    }
}
